package com.sskj.one.transaction;

import com.hjq.toast.ToastUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.one.MainPresneter;
import com.sskj.one.bean.BuyOrderBean;
import com.sskj.one.bean.GonggaoBean;
import com.sskj.one.bean.HistoryBean;
import com.sskj.one.bean.LastestBean;
import com.sskj.one.bean.MoneyBean;
import com.sskj.one.bean.MoneyListBean;
import com.sskj.one.bean.Stock;
import com.sskj.one.http.HttpConfig;
import com.sskj.one.presenter.BasePresenter;

import java.util.List;

/**
 * @author Hey
 * Create at  2019/05/21
 */
class TransactionPresenter extends BasePresenter<TransactionFragment> {

    public void getStockInfo() {
        httpService.getStockInfo()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<Stock>>>() {
                    @Override
                    public void onHTTPSuccess(HttpData<List<Stock>> data) {
//                        mView.setChart(data.getData());
                    }
                });
    }

    public void getMoneys(String buyType) {
        httpService.getMoneys()
                .tag(this)
                .execute(new JsonCallBack<HttpData<MoneyListBean>>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData<MoneyListBean> data) {
                        mView.getMoneyOK(data.getData(), buyType);
                    }
                });

    }

    public void buy(String buyMoney, String type) {
        httpService.buy(buyMoney, type)
                .tag(this)
                .execute(new JsonCallBack<HttpData<BuyOrderBean>>() {
                    @Override
                    public void onHTTPSuccess(HttpData<BuyOrderBean> data) {
                        mView.buyOK(data.getData());
                        ToastUtils.show("下单成功");
                    }
                });
    }

    public void getNewProfit() {
        httpService.getNewProfit()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<LastestBean>>>() {
                    @Override
                    public void onHTTPSuccess(HttpData<List<LastestBean>> data) {
                        mView.getLastestOK(data.getData());
                    }
                });
    }

    public void getNewOrders() {
        httpService.getNewOrders()
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<LastestBean>>>() {
                    @Override
                    public void onHTTPSuccess(HttpData<List<LastestBean>> data) {
                        mView.getLastestOK(data.getData());
                    }
                });
    }

    public void getGonggao() {
        httpService.getGonggaoList(1, 10)
                .tag(this)
                .execute(new JsonCallBack<HttpData<List<GonggaoBean>>>() {
                    @Override
                    public void onHTTPSuccess(HttpData<List<GonggaoBean>> data) {
                        mView.getGonggaoOK(data.getData());
                    }
                });

    }

    public void getLastOrder(String tran_id) {
        httpService.getLastOrder(tran_id)
                .tag(this)
                .execute(new JsonCallBack<HttpData<HistoryBean>>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData<HistoryBean> data) {
                        mView.getOrderOK(data.getData());
                    }
                });
    }

    public void getNextOrder(String tran_id) {
        httpService.getNextOrder(tran_id)
                .tag(this)
                .execute(new JsonCallBack<HttpData<HistoryBean>>(this) {
                    @Override
                    public void onHTTPSuccess(HttpData<HistoryBean> data) {
                        mView.getOrderOK(data.getData());
                    }
                });
    }

    public void getOrder(String hold_no) {
        httpService.getOrder(hold_no)
                .tag(this)
                .execute(new JsonCallBack<HttpData<HistoryBean>>(false) {
                    @Override
                    public void onHTTPSuccess(HttpData<HistoryBean> data) {
                        mView.getOrderMsgOK(data.getData());
                    }

                    @Override
                    public void onError(Response<HttpData<HistoryBean>> response) {
                        super.onError(response);
                        getOrder(hold_no);
                    }
                });
    }
}
